package com.swan.controllers;

import com.swan.beans.StatusEnum;
import com.swan.beans.UserBean;
import com.swan.models.LoginDao;
import com.swan.models.UserDao;

import java.util.List;

/**
 * User controller that will be call by javaFX page.
 */
public class UserController {

    public List<UserBean> list() {
        UserDao userDao = new UserDao();
        return userDao.list();
    }

    public boolean changePassword(String userName, String oldPassword, String newPassword) {
        return new LoginDao().changePassword(userName, oldPassword, newPassword);
    }

    public boolean removeUser(int userId){
        return new UserDao().removeUser(userId);
    }

    /**
     *
     * @param userBean
     * @return the generated userId.
     */
    public int addUserId(UserBean userBean){
        new UserDao().addUser(userBean);
        return userBean.getId();
    }

    public boolean enable(int userId){
        return updateStatus(userId,StatusEnum.ENABLE);
    }

    public boolean disable(int userId){
        return updateStatus(userId,StatusEnum.DISABLE);
    }

    private boolean updateStatus(int userId, StatusEnum statusEnum){
        return new UserDao().updateStatus(userId,statusEnum);
    }
}
